﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace Com.CMS263.Util
{
    public class EmailUtil
    {
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="strSmtpServer"></param>
        /// <param name="strFrom">发件人地址</param>
        /// <param name="strFromPass">发件人密码</param>
        /// <param name="strto">收件人</param>
        /// <param name="strSubject">主题</param>
        /// <param name="strBody">内容</param>
        public static void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody, string filepath)
        {
            System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
            if (!string.IsNullOrEmpty(filepath))
            {
                message.Attachments.Add(new Attachment(filepath));
            }
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.IsBodyHtml = true;
            client.Send(message);

            //服务器上的附件无法删除
        }
    }
}
